package com.banban.user.service.impl;

import com.banban.user.domain.UserCid;
import com.banban.user.mapper.UserCidMapper;
import com.banban.user.service.UserCidService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserCidServiceImpl extends ServiceImpl<UserCidMapper, UserCid> implements UserCidService {

    @Resource
    private UserCidMapper mapper;

    @Override
    public void updateUserCid(String id, String cid) {
        int count = count(new LambdaQueryWrapper<UserCid>().eq(UserCid::getCid, cid).eq(UserCid::getUserId, id));
        if (count == 0) {
            UserCid userCid = new UserCid();
            userCid.setCid(cid);
            userCid.setUserId(id);
            mapper.insert(userCid);
        }
    }
}
